import os
import re
import sys
import shutil
#locals = "C:/Users/jize.liu/Desktop/诛仙上传"
locals = "D:/EP14/Scence"
Disk = "Z:/AnimationSeries/A10/ANI"



for file in os.listdir(locals):
    print (file)
    if file.endswith("ma"):
        pattern = r'([A-Z][0-1][0-1]_[A-Z][A-Z][0-9][0-9])([A-Z][0-9][0-9][0-9])([a-z][0-9][0-9][0-9][0-9])_([A-Z][A-Z][A-Z]).ma'
        matches = re.search(pattern, file)
        if matches:
            group1 = matches.group(1)  # A10_EP13
            group2 = matches.group(2)  # S005
            group3 = matches.group(3)  # c0210
            group4 = matches.group(4)  # ANI
            if not os.path.exists(os.path.join(Disk,group1,group2,group3,"scenes")):
                os.makedirs(os.path.join(Disk,group1,group2,group3,"scenes"))

            shutil.copy (os.path.join(locals,file),os.path.join(Disk,group1,group2,group3,"scenes",group1 + "_" + group2 + "_" + group3 + "_" +group4 + ".ma"))
        else:
            print("No match found.")

    if file.endswith("mov"):
        pattern = r'([A-Z][0-1][0-1]_[A-Z][A-Z][0-9][0-9])([A-Z][0-9][0-9][0-9])([a-z][0-9][0-9][0-9][0-9])_([A-Z][A-Z][A-Z]).mov'
        matches = re.search(pattern, file)
        if matches:
            group1 = matches.group(1)  # A10_EP13
            group2 = matches.group(2)  # S005
            group3 = matches.group(3)  # c0210
            group4 = matches.group(4)  # ANI
            if not os.path.exists(os.path.join(Disk,group1,group2,group3,"movies")):
                os.makedirs(os.path.join(Disk,group1,group2,group3,"movies"))
            shutil.copy (os.path.join(locals,file),os.path.join(Disk,group1,group2,group3,"movies",group1 + "_" + group2 + "_" + group3 + "_" +group4 + ".mov"))
        else:
            print("No match found.")
    if file.endswith("fbx"):
        pattern = r'([A-Z][0-1][0-1]_[A-Z][A-Z][0-9][0-9])([A-Z][0-9][0-9][0-9])([a-z][0-9][0-9][0-9][0-9])_([A-Z][A-Z][A-Z])_cam.fbx'
        matches = re.search(pattern, file)
        if matches:
            group1 = matches.group(1)  # A10_EP13
            group2 = matches.group(2)  # S005
            group3 = matches.group(3)  # c0210
            group4 = matches.group(4)  # ANI
            if not os.path.exists(os.path.join(Disk,group1,group2,group3,"cache")):
                os.makedirs(os.path.join(Disk,group1,group2,group3,"cache"))
            shutil.copy (os.path.join(locals,file),os.path.join(Disk,group1,group2,group3,"cache",group1 + "_" + group2 + "_" + group3 + "_" +group4 + "_cam.fbx"))
        else:
            print("No match found.")


